/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.audit.service.plugins;

import java.util.List;

import org.apache.log4j.Logger;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.auditRule.entity.Audit;
import com.apache.auditRule.manager.AuditManager;
import com.apache.cache.util.Validator;
import com.apache.database.model.Page;
import com.apache.tools.ClassToolsUtil;

public class AuditListPluginImpl implements PluginConnector {

	private Logger log = Logger.getLogger(AuditListPluginImpl.class);

	private AuditManager auditManager;

	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		entity.setResult("true");
		Audit audit = new Audit();
		audit = (Audit) ClassToolsUtil.getInstance().convert2Bean(param.getParams(), audit);

		ParamsVo<Audit> vo = new ParamsVo<Audit>();
		vo.setObj(audit);
		vo.setMethodKey("AuditListForService");
		String rows = Validator.getDefaultStr(String.valueOf(param.getParams("rows")), "0");
		if ("0".equals(rows)) {
			List list = auditManager.getList(vo);
			entity.setEntity(list);
		} else {
			String page = Validator.getDefaultStr(String.valueOf(param.getParams("page")), "1");
			vo.setParams("pageIndex", page);
			vo.setParams("pageSize", rows);
			Page pageList = auditManager.getPageInfo(vo);
			entity.setEntity(pageList);
		}
		entity.setMessage("查询成功");
		return entity;
	}

	private String getParamStr(ParamsVo vo, String attrName) {
		return Validator.getDefaultStr(String.valueOf(vo.getParams(attrName)), "");
	}

	public void setAuditManager(AuditManager auditManager) {
		this.auditManager = auditManager;
	}

}
